package com.foo.designpattern.memento;

/**
 * com.foo.designpattern.memento
 * Created with IntelliJ IDEA.
 * Created by jiang on 2016-05-03 12:20.
 *
 * @Description 原始类
 */

public class Original {
    // 原始类中需要备份的属性：value
    private String value;

    /**
     * 构造函数：初始化属性值
     *
     * @param value
     */
    public Original(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    /**
     * 调用备忘录类，备份原始数据
     *
     * @return
     */
    public Memento createMemento() {
        return new Memento(value);
    }

    /**
     * 获取备忘录里备份的信息，恢复原始类的状态
     *
     * @param memento
     */
    public void restoreMemento(Memento memento) {
        this.value = memento.getValue();
    }

}
